package com.leo.leetcode.s100;

/**
 *
 * @author xuexiaolei
 * @version 2017年11月21日
 */
public class T28ImplementstrStr {
    public static int strStr2(String haystack, String needle) {
        if (needle.equals("")) return 0;
        int key=-1;
        for (int i = 0; i < (haystack.length() - needle.length() + 1); i++) {
            for (int j = 0; j < needle.length(); j++) {
                if (needle.charAt(j) == haystack.charAt(i+j)){
                    if (j == needle.length()-1) return i;
                }else {
                    break;
                }
            }
        }
        return key;
    }

    public static int strStr(String haystack, String needle) {
        return haystack.indexOf(needle);
    }

    public static void main(String[] args) {
        System.out.println(strStr("",""));//0
        System.out.println(strStr("","bc"));//-1
        System.out.println(strStr("abcbc",""));//0
        System.out.println(strStr("abcbc","bc"));
        System.out.println(strStr("abbbc","bb"));
    }
}
